{layout name="layout" /}

<div class="Hui-article">
    <div class="pd-20" style="min-width:860px;max-width:60%;">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a href="javascript:;" class="btn btn-success radius" onclick="duty_all('pass')">
                    <i class="Hui-iconfont">&#xe6e2;</i> 批量通过</a>
                <a href="javascript:;" class="btn btn-danger radius" onclick="duty_all('reject')">
                    <i class="Hui-iconfont">&#xe600;</i>批量驳回</a>
            </span>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort">
                <thead>
                    <tr class="text-c">
                        <th width="20px">
                            <input type="checkbox" value="" name="allcheck">
                        </th>
                        <th width="20px">ID</th>
                        <th width="80px">缩略图</th>
                        <th width="25%">文章标题</th>
                        <th width="120px">更新日期</th>
                        <th width="120px">审核状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {foreach $data as $val}
                    <tr class="text-c va-m" style="height:80px;">
                        <td>
                            <input type="checkbox" value="{$val.id}" name="checkbox[]">
                        </td>
                        <td>{$val.id}</td>
                        <td>
                            <img width="60" class="product-thumb" src="{$val.thumb}">
                        </td>
                        <td class="text-l">
                            <a href="javascript:void(0);" style="text-decoration:none" title="浏览">{$val.title}</a>
                        </td>
                        <td class="text-c">{$val.pubtime|date="Y-m-d H:i:s",###}</td>
                        <td class="td-status">
                            {eq name="$val.ispost" value="0"}
                            <span class="label label-error radius">未审核</span>
                            {else/}
                            <span class="label label-danger radius">未通过</span>
                            {/eq}
                        </td>
                        <td class="td-manage">
                            <button class="btn btn-defualt radius" type="submit" onClick="layer_show('文章详情','/admin/article/preview.html?id={$val.id}')">查看</button>
                            <button class="btn btn-success radius" type="submit" onClick="pass(this, '{$val.id}')">通过</button>
                            <button type="button" class="btn btn-danger radius" onClick="reject(this, '{$val.id}')">驳回</button>
                        </td>
                    </tr>
                    {/foreach}
                </tbody>
            </table>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20 ">
            <span class="l">共
                <strong>{$counts}</strong> 篇, {$pages} 页 </span>
            <span class="r">
                {$data->render()}
            </span>
        </div>
    </div>
</div>

<!-- 请在下方写此页面业务相关的脚本 -->
<script type="text/javascript">

    /*文章-通过审核*/
    function pass(obj, id) {
        $.post('duty', {
            'id': id,
            'ispost': 1
        }, function (data) {
            if (data.code == 2) {
                $(obj).parents("tr").remove();
                layer.msg(data.msg, {
                    icon: 6,
                    time: 1000
                });
            } else {
                layer.msg(data.msg, {
                    icon: 5,
                    time: 1000
                });
            }
        }, 'json');
    }

    /*文章-审核驳回*/
    function reject(obj, id) {
        $.post("{:url('duty')}", {
            'id': id,
            'ispost': 2
        }, function (data) {
            if (data.code == 2) {
                $(obj).parents("tr").find(".td-status").html(
                    '<span class="label label-danger radius">未通过</span>');
                layer.msg(data.msg, {
                    icon: 6,
                    time: 1000
                });
            } else {
                layer.msg(data.msg, {
                    icon: 5,
                    time: 1000
                });
            }
        }, 'json');
    }

    /*文章-批量审核通过*/
    function duty_all(action) {
        if (action=='pass') {
            msg = "通过";
        } else {
            msg = "驳回";
        }
        layer.confirm('确认'+msg+'选中条目？', function (index) {
            var checkbox = $('.text-c input[name="checkbox[]"]');
            checkbox.each(function (x) {
                if (this.checked) {
                    var obj = $(this).parents('tr').find('.td-manage').children('button');
                    var id = $(this).val();
                    if (action == 'pass') {
                        pass(obj, id);
                    } else {
                        reject(obj, id);
                    }
                }
            })
        });
    }
</script>
<!--/请在上方写此页面业务相关的脚本-->